/*
 * SeparatedCGOptimizer.h
 *
 *      Author: Jerome RD Soine and Christoph A Brand
 *      Institution: Schwarz goup, Institute for Theoretical Physics, Heidelberg University, Germany
 */

#ifndef SEPARATEDCGOPTIMIZER_H_
#define SEPARATEDCGOPTIMIZER_H_

#include "include/core/optimizer/ConjugatedGradient.h"

class SeparatedCGOptimizer: public ConjugatedGradient {
protected:
	unsigned int tot_iterations;
	unsigned int cg_block_size;
	bool first, write_fem_output_bool, write_FA_state_file_bool, write_convergence_file_bool, write_solution_bool;
	double initial_fitness;

	virtual void iterate_cg();
	virtual void adjust_first_dof();
public:
	SeparatedCGOptimizer(CellModel * CELL_MODEL,
			SubstrateModel * SUBSTRATE_MODEL, Comparator * COMPARATOR, string SOLUTION_FOLDER,
			unsigned int N_ITERATIONS, unsigned int N_THREADS, double TOLERANCE,
			double GRADIENT_SPACING, unsigned int CG_BLOCK_SIZE, bool NETWORK_FIRST) :
				ConjugatedGradient(CELL_MODEL, SUBSTRATE_MODEL, COMPARATOR, SOLUTION_FOLDER, N_ITERATIONS, N_THREADS, TOLERANCE, GRADIENT_SPACING) {cg_block_size = CG_BLOCK_SIZE; first = NETWORK_FIRST; tot_iterations = 0; write_fem_output_bool = true; write_FA_state_file_bool=true; write_convergence_file_bool=true; write_solution_bool=true;};
	virtual void run();
	virtual void write_current_state(unsigned int step_index);
	virtual void write_convergence_file(Worker * w);
	virtual void write_solution_to_file();
	virtual void write_FA_state_file(Worker * w);
	virtual void set_write_fem_output(bool write) { write_fem_output_bool = write; };
	virtual void set_write_FA_state_file(bool write) { write_FA_state_file_bool = write; };
	virtual void set_write_convergence_file(bool write) { write_convergence_file_bool = write; };
	virtual void set_write_solution(bool write) { write_solution_bool = write; };
};

#endif /* SEPARATEDCGOPTIMIZER_H_ */
